package com.moli.iov.down.command.design.factory;

import com.moli.iov.down.command.design.strategy.commandreqdto.CommandReqDtoStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.ChangeIpPortStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.ChangeIpStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.ChangePortStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.ChangeRealTimeStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.KeyEnableDisabledStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.OpenCloseDoorStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.PowerStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.RestartStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.ResumeFactoryStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.SearchCarStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.SetLeaseStrategy;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.Upgrade;
import com.moli.iov.down.command.design.strategy.commandreqdto.impl.WindowStrategy;
import com.moli.iov.down.enums.OperateTypeEnum;
import com.moli.iov.down.model.dto.remoting.CommandDto;
import com.moli.iov.down.model.dto.remoting.CommandReqDto;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * CommandReqDto 策略工厂
 * </p>
 *
 * @author: zql
 * @Date: 2018/12/28 12:17
 */
public class CommandReqDtoFactory {
    private static  final Logger logger = LoggerFactory.getLogger(CommandReqDtoFactory.class);

    private static final Map<Integer, CommandReqDtoStrategy> STRATEGY_MAP = new HashMap<>();

    static{
        STRATEGY_MAP.put(OperateTypeEnum.OPEN_DOOR.getFlag(), new OpenCloseDoorStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.CLOSE_DOOR.getFlag(), new OpenCloseDoorStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.SEARCH_CAR.getFlag(), new SearchCarStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.SET_LEASE.getFlag(), new SetLeaseStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.SET_UN_LEASE.getFlag(), new SetLeaseStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.KEY_ENABLE.getFlag(), new KeyEnableDisabledStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.KEY_DISABLED.getFlag(), new KeyEnableDisabledStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.OPEN_POWER.getFlag(), new PowerStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.POWER_OFF.getFlag(), new PowerStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.RESTART.getFlag(), new RestartStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.RESUME_FACTORY.getFlag(), new ResumeFactoryStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.CHANGE_IP.getFlag(), new ChangeIpStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.CHANGE_PORT.getFlag(), new ChangePortStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.CHANGE_IP_PORT.getFlag(), new ChangeIpPortStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.FREQUENCY.getFlag(), new ChangeRealTimeStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.UPGRADE.getFlag(), new Upgrade());
        STRATEGY_MAP.put(OperateTypeEnum.OPEN_WINDOW.getFlag(), new WindowStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.CLOSE_WINDOW.getFlag(), new WindowStrategy());
        STRATEGY_MAP.put(OperateTypeEnum.STOP_WINDOW.getFlag(), new WindowStrategy());
    }

    private CommandReqDtoFactory(){}

    public static CommandDto getCommandReqDto(CommandReqDto commandReqDto){
        CommandReqDtoStrategy commandReqDtoStrategy = STRATEGY_MAP.get(commandReqDto.getOperateType());
        if(null == commandReqDtoStrategy){
            logger.error("策略工厂生成CommandReqDto 失败 入参 commandReqDto: {} ",
                commandReqDto);
            return null;
        }
        return commandReqDtoStrategy.make(commandReqDto);
    }
}
